package com.winning.yanghao.designpattern.singleton.lazy;

/**
 * 懒汉模式:内部类，性能和LazyTwo差不多
 * @author Louis Yang
 */
public class LazyThree {

    //false：没有被实例化，true：已被实例
    private static boolean initialized = false;

    private LazyThree() {
        synchronized (LazyThree.class) {
            if (!initialized) {
                initialized = !initialized;
            } else {
                throw new RuntimeException("单例已被侵犯!");
            }
        }
    }

    public static final LazyThree getInstance() {
        return LazyHolder.LAZY;
    }

    private static class LazyHolder {
        private static LazyThree LAZY = new LazyThree();
    }

}
